<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Sistema de Administraci&oacute;n de Condominios - Mantenimiento de Residentes</title>
<%@include file="include/header.jsp" %>
</head>
<body>
<%@include file="include/menu.jsp" %>

    	<%		
		Persona vo = (Persona)session.getAttribute("user");
		
		if (vo== null){
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
			return;
		}
	  %>
<div class="container">
	<div class="hero-unit" align="center">
	    	<h2><strong>Busqueda de Residentes</strong></h2><br>
	 </div>
		  
<%@page import="java.util.ArrayList,condominios.modelo.Persona"%>
<form method="post" action="ResidenteUpdateServlet">
	<div class="row">
		<div class="col-md-10 col-md-offset-1">
		<%	
				
			ArrayList<Persona> personasFull = (ArrayList<Persona>) request.getAttribute("RESIDENTES");
			if (personasFull != null) {%>
		<div class="table-responsive">
			<p>La cantidad de registros encontrados son: <%=personasFull.size()%></p>
			<table id="tablaBuscar" class="table table-striped table-bordered table-condensed">
  				<tr class="active" id = "fila1">
  					<th id= "celda1">Id Per</th>
  					<th>DNI</th>
  					<th>Nombres</th>
  					<th>Apellido Paterno</th>
  					<th>Apellido Materno</th>
  					<th>Email</th>
  					<th>Perfil</th>
  					<th></th>
  				</tr>
  				<% 
  				int minFila = (int) request.getAttribute("MINROW");
  				int maxFila = (int) request.getAttribute("MAXROW");
  			
  				for (int i=minFila; i<=maxFila; i++) {
  				%>
  				<tr>
  					<td align="center"><%=personasFull.get(i).getIdPersona()%></td>
  					<td><%=personasFull.get(i).getDni()%></td>
  					<td><%=personasFull.get(i).getNombres()%></td>
  					<td><%=personasFull.get(i).getApellidoPaterno()%></td>
  					<td><%=personasFull.get(i).getApellidoMaterno()%></td>
  					<td><%=personasFull.get(i).getEmail()%></td>
  					<td><%=personasFull.get(i).obtenerCadenaPerfil(personasFull.get(i).getIdPerfil())%></td>
  					<td>
  						<button type="submit" class="btn btn-default" aria-label="Left Align" name="residente<%=Integer.toString(personasFull.get(i).getIdPersona())%>">
  						<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
						</button>
						<button type="submit" class="btn btn-default" aria-label="Left Align" name="residented<%=Integer.toString(personasFull.get(i).getIdPersona())%>">
  						<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
						</button>
  					
  					</td>
  					
  				</tr>
  				<%
  						}
  				%> 					
			</table>
						
				</div>
			</div>
		</form>				
			<div class="row">		
  			<div class="col-md-4 col-md-offset-1" align="left">
  			<form method="post" action="ResidentePaginarServlet">
  			
  				<%int numPag = (int) request.getAttribute("NUMPAG");%>
  				<nav>
			  	<ul class="pagination">
			  	<%if (numPag ==1) {
			  	%>
			  		 <li class="disabled">
			      		<a href="<%=request.getContextPath()%>/ResidentePaginarServlet?idPag=<%=numPag%>" aria-label="Previous">
			        		<span aria-hidden="true">&laquo;</span>
			      		</a>
			    	</li>
			  	<%	
			  	} else {%>
			  		<li>
			      		<a href="<%=request.getContextPath()%>/ResidentePaginarServlet?idPag=<%=numPag-1%>" aria-label="Previous">
			        		<span aria-hidden="true">&laquo;</span>
			      		</a>
			    	</li>
			  	
			  	<%	
			  	}
			  		%>			  				   
			    <% 
  				int numPaginas = (int) request.getAttribute("NUMEROPAGINAS");
			    
  				
  				for (int i=1; i<=numPaginas; i++) {
  					if (i==numPag) {
  						%>
  					    <li class="active"><a href="<%=request.getContextPath()%>/ResidentePaginarServlet?idPag=<%=i%>"><%=i%></a></li>
  							    
  					    <% } 
  					    else {
  					    %>
					    <li><a href="<%=request.getContextPath()%>/ResidentePaginarServlet?idPag=<%=i%>"><%=i%></a></li>
							    
					    <% }
  					
  						}%>
  						
  				<%if (numPag == numPaginas) {
			  	%>
			  		 <li class="disabled">
			      		<a href="<%=request.getContextPath()%>/ResidentePaginarServlet?idPag=<%=numPag%>" aria-label="Next">
			        		<span aria-hidden="true">&raquo;</span>
			      		</a>
			    	</li>
			  	<%	
			  	} else {%>
			  		<li>
			      		<a href="<%=request.getContextPath()%>/ResidentePaginarServlet?idPag=<%=numPag+1%>" aria-label="Next">
			        		<span aria-hidden="true">&raquo;</span>
			      		</a>
			    	</li>			  	
			  	<%	
			  	}
			  		%>		
			  </ul>
			</nav>
			</form>
  			</div>
  			
  			<div class="col-md-6" align="right">
  			<form id = "formaPaginar" method="post" action="ResidenteCambiarFilasServlet">
  				Items por pagina: <select id= "selCanId" name = "selCanId" onchange="irServletBuscar()">
  					<%if (session.getAttribute("CANTIDAD_FILAS").equals(10)){
  						%>
  					
					<option value="10">10</option>
					<option value="5">5</option>
					<option value="20">20</option>
					<%} 
  					else {
  					
  						if(session.getAttribute("CANTIDAD_FILAS").equals(20)){%>
  						<option value="20">20</option>
						<option value="5">5</option>
						<option value="10">10</option>	
  						<%	
  						}
  						else {%>
  							<option value="5">5</option>
  							<option value="10">10</option>
  							<option value="20">20</option><%
  						}						
  					}					
					%>					
				</select>
				
				<script>
				function irServletBuscar() {	
					
				    document.getElementById("formaPaginar").submit();				    				    
				}
								
				</script> 
				</form>			 
  				</div>
			</div>		
		</div>	
		
			<%
  				}
  				%>  								
</div>
	
</body>
	 <footer>
	 <div class="container">
		 <div class="row">		
	  		<div class="col-md-12" align="center">			 	
	        		<p>&copy; Java Tigers 2015</p>				
			</div>
				
		</div>
		
	</div>
	 </footer>
</html>